{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Hello World\n",
    "====\n",
    "就是一句话的事\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100 100.4 100.4\n"
     ]
    }
   ],
   "source": [
    "#为什么该cell中type无法输出变量的类型，一个时可以\n",
    "a=100\n",
    "type(a)\n",
    "j=0.4\n",
    "type(j)\n",
    "b=a+j\n",
    "type(b)\n",
    "print(a,b,b.real)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, world!\n",
      "It's a big dog.\n",
      "hello!\n"
     ]
    }
   ],
   "source": [
    "#单引号，双引号，字符串\n",
    "c='Hello, world!'\n",
    "print(c)\n",
    "c1=\"It's a big dog.\"\n",
    "print(c1)\n",
    "c2=\"hello!\"\n",
    "print(c2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'HELLO, WORLD!'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"'\""
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c1[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "It's a dog!\n"
     ]
    }
   ],
   "source": [
    "c3='It\\'s a dog!'\n",
    "print(c3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello!\\nWorld!\n"
     ]
    }
   ],
   "source": [
    "c4=r'Hello!\\nWorld!'\n",
    "print(c4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My first python\n",
      "My first python\n",
      "My first python\n",
      "My first python\n",
      "My first python\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('My first python\\n'*5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#type为什么只能输出最后一个变量的类型\n",
    "b=(1>2)\n",
    "print(b)\n",
    "type(b)\n",
    "c='test'\n",
    "type(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "Xx\n",
      "张三\n",
      "王五\n"
     ]
    }
   ],
   "source": [
    "#列表 可变 []\n",
    "students=['张三','李四','王五','Xx']\n",
    "a=len(students)\n",
    "print(a)\n",
    "print(students[a-1])\n",
    "print(students[0])\n",
    "print(students[-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "Xx\n",
      "张三\n",
      "王五\n"
     ]
    }
   ],
   "source": [
    "#元组 不可变 ()\n",
    "students=('张三','李四','王五','Xx')\n",
    "a=len(students)\n",
    "print(a)\n",
    "print(students[a-1])\n",
    "print(students[0])\n",
    "print(students[-2])\n",
    "#students[2]='小刘'\n",
    "#print(students[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#set\n",
    "a=[1,2,3,4]\n",
    "set(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a', 'c', 'e', 'd', 'g', 'f', 'b'}\n",
      "{'c', 'm', 'd', 'f'}\n",
      "{'c', 'd', 'f'}\n",
      "{'a', 'c', 'e', 'm', 'd', 'g', 'f', 'b'}\n",
      "{'g', 'a', 'b', 'e'}\n"
     ]
    }
   ],
   "source": [
    "#集合 set()\n",
    "a=set('abcdefgaaaggg')\n",
    "print(a)\n",
    "b=set('cdfm')\n",
    "print(b)\n",
    "#交集\n",
    "c=a&b\n",
    "print(c)\n",
    "#并集\n",
    "c=a|b\n",
    "print(c)\n",
    "#差集\n",
    "c=a-b\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#字典 {}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "30.14,50.22\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "price_str is str type!",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-7d73cc4500f3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      9\u001b[0m     \u001b[0mprice_str\u001b[0m\u001b[1;33m+=\u001b[0m\u001b[1;36m1.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m     \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'price_str is str type!'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: price_str is str type!"
     ]
    }
   ],
   "source": [
    "#if else elif\n",
    "price_str='30.14,50.22'\n",
    "print(type(price_str))\n",
    "if isinstance(price_str,str):\n",
    "    print(price_str)\n",
    "if isinstance(price_str,int)and price_str>0:\n",
    "    price_str+=1\n",
    "elif isinstance(price_str,float):\n",
    "    price_str+=1.0\n",
    "else:\n",
    "    raise TypeError('price_str is str type!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "else\n"
     ]
    }
   ],
   "source": [
    "#if elif else \n",
    "test=0\n",
    "if (test>0):\n",
    "   print('if')\n",
    "#lif (test==0):\n",
    " # print('elif')\n",
    "else:\n",
    "   print('else')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "else\n"
     ]
    }
   ],
   "source": [
    "#test if elif  if和elif组合可以别处多种情况，除这些情况外，其余情况为else；将条件判断从两种扩展到很多种\n",
    "test=5\n",
    "if test==1:\n",
    "    print(test)\n",
    "elif test==2:\n",
    "    print(test)\n",
    "elif test==3:\n",
    "    print(test)\n",
    "elif test==4:\n",
    "    priont(test)\n",
    "else:\n",
    "    print('else')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<built-in method format of str object at 0x000001E6A73A9998>\n",
      "abcdefg\n",
      "abc1efg\n",
      "abcdefg\n"
     ]
    }
   ],
   "source": [
    "#字符串是不可变对象，对字符串操作的API都是返回一个新的字符串，原字符串不变\n",
    "str_test='abc1efg'\n",
    "print(str_test.format)\n",
    "str_test1=str_test.replace('1','d')\n",
    "print(str_test.replace('1','d'))\n",
    "print(str_test)\n",
    "print(str_test1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<built-in method format of str object at 0x000001E6A32C4228>\n",
      "true\n",
      "2090091692584\n"
     ]
    }
   ],
   "source": [
    "a='true'\n",
    "print(a.format)\n",
    "print(format(a))\n",
    "print(id(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2,4,5,6,8,10\n",
      "['2', '4', '5', '6', '8', '10']\n",
      "['2', '4', '6', '8', '10']\n"
     ]
    }
   ],
   "source": [
    "# []应该为list，列表；split()分割字符串；remove 移除函数\n",
    "price_str='2,4,5,6,8,10'\n",
    "price_array=price_str.split(',')\n",
    "print(price_str)\n",
    "print(price_array)\n",
    "set(price_array)\n",
    "price_array.remove('5')\n",
    "print(price_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "end\n"
     ]
    }
   ],
   "source": [
    "#if elif else python会优先执行最先满足条件的代码\n",
    "x=5\n",
    "if x==10:\n",
    "    print('first')\n",
    "elif x>8:\n",
    "    print('second')\n",
    "elif x>6:\n",
    "    print('third')\n",
    "else:\n",
    "    print('end')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['2', '4', '6', '8', '10']\n",
      "['20180809', '20180810', '20180811', '20180812', '20180813']\n",
      "5\n",
      "20180814\n",
      "['20180809', '20180810', '20180811', '20180812', '20180813', '20180814', '20180815', '20180816', '20180817', '20180818']\n",
      "['20180809', '20180810', '20180811', '20180812', '20180813']\n",
      "  \n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "#循环控制 for   无用的变量python建议使用_声明，减少变量数\n",
    "print(price_array)\n",
    "date_array=[]\n",
    "date_base=20180809\n",
    "for _ in range(0,len(price_array)):\n",
    "    date_array.append(str(date_base))\n",
    "    date_base+=1\n",
    "print(date_array)\n",
    "\n",
    "#循环控制 while\n",
    "price_cnt=len(price_array)\n",
    "print(price_cnt)\n",
    "print(date_base)\n",
    "while price_cnt>0:\n",
    "    date_array.append(str(date_base))\n",
    "    date_base+=1\n",
    "    price_cnt-=1\n",
    "print(date_array)\n",
    "\n",
    "#python更建议的写法 使用列表推导式来完成\n",
    "date_base=20180809\n",
    "date_arraytest=[str(date_base+ind)for ind, _ in enumerate(price_array)]\n",
    "print(date_arraytest)\n",
    "\n",
    "print('  ')\n",
    "enu1=enumerate(price_array)\n",
    "list(enu1)\n",
    "enu2=enumerate(date_array,start=1)\n",
    "list(enu2)\n",
    "print(list(enu1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
